﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.ProcessFlow;
using emp.BLL;
using emp.Model;
using emp.Utility;
using emp.ProcessFlow;
using emp.ProcessFlow.SysManage;

public partial class crm_campaign_NameList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            if (Request["cur_page"] != null)
            {
                filterlist.PageIndex = Convert.ToInt32(Request["cur_page"].ToString());
            }
            init(CreateDate_start1.Text, CreateDate_start2.Text, filter_name.Text);
        }

    }
    protected void search_Click(object sender, EventArgs e)
    {

    }
    protected void filterlist_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView theGrid = sender as GridView;
        int newPageIndex = 0;

        if (-2 == e.NewPageIndex)
        {
            TextBox txtNewPageIndex = null;
            GridViewRow pagerRow = theGrid.BottomPagerRow;
            if (null != pagerRow)
            {
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
            }
            if (null != txtNewPageIndex)
            {
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            newPageIndex = e.NewPageIndex;
        }

        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        theGrid.PageIndex = newPageIndex;
        init(CreateDate_start1.Text, CreateDate_start2.Text, filter_name.Text);
    }
    private void init(string start, string end, string name)
    {


        Lists list = new Lists();
        // IList datalist = list.getListConditionLists(start, end, name);
        IList datalist = list.getListLists(start, end, name,
                                                    UserController.GetUserSession() != null
                                                        ? UserController.GetUserSession().UserID
                                                        : 0);
        filterlist.DataSource = datalist;
        filterlist.DataBind();
        PageUtil.setPageCount(filterlist, datalist.Count);
    }
    protected void search_Click1(object sender, EventArgs e)
    {
        init(CreateDate_start1.Text, CreateDate_start2.Text, filter_name.Text);

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("FilterAdd.aspx");

    }
    protected void butsubmit_Click(object sender, EventArgs e)
    {
        if (Request.Form["chOne"] != null)
        {
            string ids = Request.Form["chOne"].ToString();
            Page.RegisterStartupScript("ggg", " <script> window.opener.document.getElementById('hidsel').value ='" + ids + "';window.opener.butonclick();window.close(); </script>");
        }
        else
        {
            Page.RegisterStartupScript("ggg", "<script>window.close();</script>");
        }
    }
}